package com.example.prom.utils;

import com.example.prom.ok.y2022.enums.ResponseErrorCodeEnum;
import lombok.Data;

import java.beans.ConstructorProperties;
import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {
    private int code = 0;
    private String msg = "";
    private String detailMsg = "";
    private T data;

    public static ResponseResult success() {
        return success(new Object());
    }

    public static <T> ResponseResult success(T data) {
        return build(0, "", "", data);
    }

    public static ResponseResult failure(int code, String msg) {
        return failure(code, msg, "");
    }

    public static ResponseResult failure(String msg) {
        return failure(-1, msg, (String)"");
    }

    public static ResponseResult failure(String msg, String detailMsg) {
        return failure(-1, msg, (String)detailMsg);
    }

    public static ResponseResult failure(int code, String msg, String detailMsg) {
        return build(code, msg, detailMsg, new Object());
    }

    public static <T> ResponseResult build(int code, String msg, String detailMsg, T data) {
        return new ResponseResult(code, msg, detailMsg, data);
    }
    public static <T> ResponseResult build(ResponseErrorCodeEnum errorCodeEnum, T data) {
        return new ResponseResult(errorCodeEnum.getCode(), errorCodeEnum.getMsg(), errorCodeEnum.getMsg(), data);
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getDetailMsg() {
        return this.detailMsg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setDetailMsg(String detailMsg) {
        this.detailMsg = detailMsg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseResult() {
    }

    @ConstructorProperties({"code", "msg", "detailMsg", "data"})
    private ResponseResult(int code, String msg, String detailMsg, T data) {
        this.code = code;
        this.msg = msg;
        this.detailMsg = detailMsg;
        this.data = data;
    }

}